<template>
  <div class="box">
        <div class="headr">
            <h2>欢迎注册QQ</h2>
            <h4>每一天，乐在沟通。<a href="#">免费靓号</a></h4>
        </div>
        <inputdom 
            rule="^\w{3,10}$"
            err_message="请输入正确用户名"
            type="text" ico="iconfont icon-qq1" placeholder="昵称" id="name"
            @valueChanged="subname"
        ></inputdom>
        <inputdom 
            rule="^\d{3,11}$"
            err_message="请输入正确的密码"
            ico="iconfont icon-suotou" type="password" placeholder="密码" id="pass"
            @valueChanged="subpass"
        ></inputdom>
        
        <div class="foot">
            <select name="hao" id="hao">
               <option value="" selected>+86</option>
               <option value="">+85</option>
               <option value="">+88</option>
               <option value="">+87</option>
            </select>
            <inputdom 
                rule="^\d{3,11}$"
                err_message="请输入正确的手机号码"
                ico="iconfont icon-shouji" type="text" placeholder="手机号码" class="iphone"
                @valueChanged="subhone"
            ></inputdom>    
        </div>
        <div class="btnWrapper">
            <Authbtn btnText="立即注册" @clickBtn="submitReg"></Authbtn>
        </div>
    </div>
</template>

<script>
import inputdom from '../components/inputDom.vue'
import Authbtn from '../components/Authbtn.vue'
export default {
    data(){
        return {
            name:"",
            pass:"",
            nickname:""
        }
    },
    components:{
        inputdom,
        Authbtn
    },
    methods:{
        submitReg() {
            if (!this.name || !this.pass || !this.nickname) {
                this.$toast.fail("请输入完整信息")
                return
            }
            this.$axios({
                url:"http://liangwei.tech:3000/register",
                method:'post',
                data:{
                    username:this.name,
                    password:this.pass,
                    nickname:this.nickname
                }
            }).then((res)=>{
                console.log(res);
                const {data,message,status} = res.data
                if (message=="注册成功") {
                    this.$toast.success(message)
                    this.$router.push("/")
                }else {
                    this.$toast.fail(message)
                }
            })
        },
        subname(username) {
            this.name = username
        },
        subpass(password) {
            this.pass = password
        },
        subhone(nickname) {
            this.nickname = nickname
        }
    }
}
</script>

<style lang="less" scoped>
    .box {
        width: 360px;
        margin:100px auto;
        border: 1px solid #00f;
        padding: 0 15px;
        .headr {
             margin: 15px 0px 0px 18px;
            h4 {
                display: flex;
                justify-content: space-between;
                 margin: 0px 0px 5px;
            }
        }
        .foot {
            width: 300px;
            margin:0 0 20px 20px;
            display: flex;
            justify-content: space-between;
            #hao {
                height: 30px;
            }
            .inputWrapper {
                 margin: 0;
            }
        }
        .btnWrapper {
            width: 300px;
            margin: auto;
            button {
                width: 300px;
                height: 40px;
                background-color: #cc3300;
                color: white;
                font-size: 14px;
                border: none;
                border-radius: 6px;
                margin-bottom: 20px;
            }
        }
    }
</style>